using UnityEngine;
using QFramework;
using QFramework.Example;

namespace XCZProject
{
	public partial class Bomb : GameplayObject
	{
		public static void Excute()
		{
			// 获取场景内所有的敌人，销毁
			var enemys=FindObjectsByType<Enemy>(FindObjectsInactive.Exclude, FindObjectsSortMode.None);
			//print("一共发现敌人数量："+enemys.Length);
			foreach (var enemy in enemys)
			{
				//enemy.Hurt(Global.BombDamage.Value);
				DamageSystem.CalculateDamage(Global.BombDamage.Value,enemy);
			}
				
			AudioKit.PlaySound("bomb");
			UIGamePanel.flashScreen.Trigger();
			CameraController.Shake();
		}
		
		private void OnTriggerEnter2D(Collider2D collider2D)
		{
			// 当碰撞的物体拥有“拾取范围”脚本时，则证明经验球碰到了玩家，增加经验并且删除该物体
			if (collider2D.GetComponent<CollectableArea>())
			{
				Excute();
				this.DestroyGameObjGracefully();
			}
		}

		protected override Collider2D Collider2D => SelfCollider2D;
	}
}
